package cn.qu.v1.platform.aop;

import cn.qu.v1.platform.inject.ProxyBeanDef;
import net.sf.cglib.proxy.MethodProxy;

import java.util.List;

/**
 * Created by zh on 17/1/18.
 */
public class MethodProxyInvoker {
    private MethodProxy methodProxy;
    private List<ProxyBeanDef> proxyBeanList;

    public MethodProxyInvoker(MethodProxy methodProxy, List<ProxyBeanDef> proxyBeanList) {
        this.methodProxy = methodProxy;
        this.proxyBeanList = proxyBeanList;
    }

    public Object invokeSuper(Object target, Object[] args) {
        try {

            Invoker invoker = new Invoker(methodProxy);

            for (int i = 0; i < proxyBeanList.size(); i++) {
                ProxyBeanDef def = proxyBeanList.get(i);

                invoker = new Invoker(invoker, def);

            }

            return invoker.invoke(target, args);

//            return def.getMethod().invoke(def.getObj(), new Invoker(methodProxy), target, args);

//            return methodProxy.invokeSuper(target, args);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }
}
